import { runCommand } from ".";

export default {
    canUndo: true,
    execute: (context, options, isUndo) => {
        runCommand(context, options, isUndo, (sheet, options) => {
            const { selections } = options;
            const leftCol = sheet.getViewportLeftColumn(1);
            sheet.suspendPaint();
            selections.forEach(range => {
                const {col,colCount} = range;
                for(let c=0;c<colCount;c++){
                    sheet.setColumnVisible(col+c, true);
                }
                if(colCount===1 && col===leftCol){
                    sheet.setColumnVisible(col-1, true);
                    sheet.showColumn(col-1, GC.Spread.Sheets.HorizontalPosition.left);
                }
            })
            sheet.resumePaint();
        })  
    }
};